////////////////////////////////////////////////////////////////////////////////
//
//  FLEX USER GROUP HOKURIKU
//  Copyright 2009 Flex User Group Hokuriku
//  All Rights Reserved.
// 
//  NOTICE: Flex User Group Hokuriku permits you to use, 
//  modify, and distribute this file 
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////
package net.fxug.hokuriku.chocolat.utils
{
    import org.flexunit.assertThat;
    import org.hamcrest.core.isA;
    import org.hamcrest.date.dateEqual;

    public class DatetimeUtilTest
    {
        private var d:Date = new Date(2010, 11, 12, 11, 15, 30, 30);

        public function DatetimeUtilTest()
        {
        }

        [Test]
        public function testGetTimeToDateNotNull():void
        {
            assertThat(DatetimeUtil.getTimeToDate(d), isA(11 * 60 + 15));
        }

        [Test]
        public function testGetYYYMMDDtoDate():void
        {
            assertThat(DatetimeUtil.getYYYMMDDtoDate(d), isA("2010/12/12"));
        }

        [Test]
        public function testGetYYYMMDDHHNNSStoDate():void
        {
            assertThat(DatetimeUtil.getYYYMMDDHHNNSStoDate(d), isA("2010/12/12 11:15:30"));
        }

        // null値
        [Test]
        public function testGetTimeToDateNull():void
        {
            assertThat(DatetimeUtil.getTimeToDate(null), isA(-1));
        }

        [Test]
        public function testGetYYYMMDDtoDateNull():void
        {
            assertThat(DatetimeUtil.getYYYMMDDtoDate(null), isA(null));
        }

        [Test]
        public function testGetYYYMMDDHHNNSStoDateNull():void
        {
            assertThat(DatetimeUtil.getYYYMMDDHHNNSStoDate(null), isA(null));
        }

        [Test]
        public function tetRoundDown():void
        {
            var d:Date = new Date(2009, 11, 11, 4, 23, 11);
            var d2:Date = new Date(2009, 11, 11, 4, 23, 11, 12);
            assertThat(d, isA(dateEqual(DatetimeUtil.roundDownByMillsecond(d2))));
        }
    }
}